﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


namespace PRE
{
    public partial class Form1 : RibbonForm
    {

        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static UTL.Session _sss = new UTL.Session();
        public static string _User;

        public Form1()
        {
            InitializeComponent();
            InitSkinGallery();

        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        private void iNew_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmBenhnhan) return;
            var frm = new catalog.FrmBenhnhan() { MdiParent = this };

            frm.Show();


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            btdangnhap_ItemClick(null, null);
        }

        private void EnableMenu()
        {
            switch (_sss.Role)
            {
                case UTL.Session.Roles.Admin:
                    //bac si kham
                    btDonthuoc.Enabled = true;
                    phieukhambacsi.Enabled = true;
                    //tiep nhan benh
                    btPhieukham.Enabled = true;
                    btbenhnhan1.Enabled = true;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = true;
                    btphieusudungdichvu1.Enabled = true;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = true;
                    //quan ly thong tin
                    btNhanvien.Enabled = true;
                    btDoituong.Enabled = true;
                    btTrangthaikham.Enabled = true;
                    btChucdanh.Enabled = true;
                    btPhong.Enabled = true;
                    btDonvitinh.Enabled = true;
                    btdichvucls.Enabled = true;
                    btikhoa.Enabled = true;
                    btidongiadvcls.Enabled = true;
                    btloaidichvu.Enabled = true;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = true;
                    btTKdsNV.Enabled = true;

                    break;

                case UTL.Session.Roles.bacsikham:
                    //bac si kham
                    btDonthuoc.Enabled = true;
                    phieukhambacsi.Enabled = true;
                    //tiep nhan benh
                    btPhieukham.Enabled = false;
                    btbenhnhan1.Enabled = false;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = false;
                    btphieusudungdichvu1.Enabled = false;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = false;
                    //quan ly thong tin
                    btNhanvien.Enabled = false;
                    btDoituong.Enabled = false;
                    btTrangthaikham.Enabled = false;
                    btChucdanh.Enabled = false;
                    btPhong.Enabled = false;
                    btDonvitinh.Enabled = false;
                    btdichvucls.Enabled = false;
                    btikhoa.Enabled = false;
                    btidongiadvcls.Enabled = false;
                    btloaidichvu.Enabled = false;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = false;
                    btTKdsNV.Enabled = false;

                    break;

                case UTL.Session.Roles.tiepnhanbenh:
                    //bac si kham
                    btDonthuoc.Enabled = false;
                    phieukhambacsi.Enabled = false;
                    //tiep nhan benh
                    btPhieukham.Enabled = true;
                    btbenhnhan1.Enabled = true;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = false;
                    btphieusudungdichvu1.Enabled = false;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = false;
                    //quan ly thong tin
                    btNhanvien.Enabled = false;
                    btDoituong.Enabled = false;
                    btTrangthaikham.Enabled = false;
                    btChucdanh.Enabled = false;
                    btPhong.Enabled = false;
                    btDonvitinh.Enabled = false;
                    btdichvucls.Enabled = false;
                    btikhoa.Enabled = false;
                    btidongiadvcls.Enabled = false;
                    btloaidichvu.Enabled = false;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = false;
                    btTKdsNV.Enabled = false;
                    break;
                case UTL.Session.Roles.vienphi:
                    //bac si kham
                    btDonthuoc.Enabled = false;
                    phieukhambacsi.Enabled = false;
                    //tiep nhan benh
                    btPhieukham.Enabled = false;
                    btbenhnhan1.Enabled = false;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = true;
                    btphieusudungdichvu1.Enabled = true;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = false;
                    //quan ly thong tin
                    btNhanvien.Enabled = false;
                    btDoituong.Enabled = false;
                    btTrangthaikham.Enabled = false;
                    btChucdanh.Enabled = false;
                    btPhong.Enabled = false;
                    btDonvitinh.Enabled = false;
                    btdichvucls.Enabled = false;
                    btikhoa.Enabled = false;
                    btidongiadvcls.Enabled = false;
                    btloaidichvu.Enabled = false;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = false;
                    btTKdsNV.Enabled = false;
                    break;

                case UTL.Session.Roles.khamcanlamsan:
                    //bac si kham
                    btDonthuoc.Enabled = false;
                    phieukhambacsi.Enabled = false;
                    //tiep nhan benh
                    btPhieukham.Enabled = false;
                    btbenhnhan1.Enabled = false;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = false;
                    btphieusudungdichvu1.Enabled = false;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = true;
                    //quan ly thong tin
                    btNhanvien.Enabled = false;
                    btDoituong.Enabled = false;
                    btTrangthaikham.Enabled = false;
                    btChucdanh.Enabled = false;
                    btPhong.Enabled = false;
                    btDonvitinh.Enabled = false;
                    btdichvucls.Enabled = false;
                    btikhoa.Enabled = false;
                    btidongiadvcls.Enabled = false;
                    btloaidichvu.Enabled = false;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = false;
                    btTKdsNV.Enabled = false;
                    break;
                case UTL.Session.Roles.quanlythongtin:
                    //bac si kham
                    btDonthuoc.Enabled = false;
                    phieukhambacsi.Enabled = false;
                    //tiep nhan benh
                    btPhieukham.Enabled = false;
                    btbenhnhan1.Enabled = false;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = false;
                    btphieusudungdichvu1.Enabled = false;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = false;
                    //quan ly thong tin
                    btNhanvien.Enabled = true;
                    btDoituong.Enabled = true;
                    btTrangthaikham.Enabled = true;
                    btChucdanh.Enabled = true;
                    btPhong.Enabled = true;
                    btDonvitinh.Enabled = true;
                    btdichvucls.Enabled = true;
                    btikhoa.Enabled = true;
                    btidongiadvcls.Enabled = true;
                    btloaidichvu.Enabled = true;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = false;
                    btTKdsNV.Enabled = false;
                    break;
                case UTL.Session.Roles.thongkebaocao:
                    //bac si kham
                    btDonthuoc.Enabled = false;
                    phieukhambacsi.Enabled = false;
                    //tiep nhan benh
                    btPhieukham.Enabled = false;
                    btbenhnhan1.Enabled = false;
                    //Vien phi
                    btPhieuthanhtoan.Enabled = false;
                    btphieusudungdichvu1.Enabled = false;
                    //bac si kham can lam san
                    bbicanlamsan.Enabled = false;
                    //quan ly thong tin
                    btNhanvien.Enabled = false;
                    btDoituong.Enabled = false;
                    btTrangthaikham.Enabled = false;
                    btChucdanh.Enabled = false;
                    btPhong.Enabled = false;
                    btDonvitinh.Enabled = false;
                    btdichvucls.Enabled = false;
                    btikhoa.Enabled = false;
                    btidongiadvcls.Enabled = false;
                    btloaidichvu.Enabled = false;
                    //thong ke bao cao
                    btPhieukhamtheotrangthai.Enabled = true;
                    btTKdsNV.Enabled = true;
                    break;
                default:
                    break;
            }
        }

        private void btThuoc_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmThuoc) return;
            var frm = new catalog.FrmThuoc() { MdiParent = this };

            frm.Show();
        }

        private void btCothuoc_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmCothuoc) return;
            var frm = new catalog.FrmCothuoc() { MdiParent = this };

            frm.Show();
        }

        private void btLoaithuoc_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmLoaithuoc) return;
            var frm = new catalog.FrmLoaithuoc() { MdiParent = this };

            frm.Show();
        }

        private void btDongiathuoc_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmDongiathuoc) return;
            var frm = new catalog.FrmDongiathuoc() { MdiParent = this };

            frm.Show();
        }

        private void btBenhnhan_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmBenhnhan) return;
            var frm = new catalog.FrmBenhnhan() { MdiParent = this };

            frm.Show();
        }

        private void btNhanvien_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmNhanvien) return;
            var frm = new catalog.FrmNhanvien() { MdiParent = this };

            frm.Show();
        }

        private void barDongtacca_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();
        }

        private void btThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        private void btQuyen_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmQuyen) return;
            var frm = new catalog.FrmQuyen() { MdiParent = this };

            frm.Show();
        }

        private void btBenhnhan_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmBenhnhan) return;
            var frm = new catalog.FrmBenhnhan() { MdiParent = this };

            frm.Show();
        }

        private void btNhanvien_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmNhanvien) return;
            var frm = new catalog.FrmNhanvien() { MdiParent = this };

            frm.Show();
        }

        private void btDonthuoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmDonthuoc) return;
            var frm = new catalog.FrmDonthuoc() { MdiParent = this };

            frm.Show();
        }

        private void btphieusudungdv_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmPhieusudungdichvu) return;
            var frm = new catalog.FrmPhieusudungdichvu() { MdiParent = this };

            frm.Show();
        }

        private void btPhieukham_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmTiepnhanbenh) return;
            var frm = new catalog.FrmTiepnhanbenh() { MdiParent = this };

            frm.Show();
        }

        private void btPhieuthanhtoan_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmPhieuthanhtoan) return;
            var frm = new catalog.FrmPhieuthanhtoan() { MdiParent = this };

            frm.Show();
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmDongiadichvu_cls) return;
            var frm = new catalog.FrmDongiadichvu_cls() { MdiParent = this };

            frm.Show();
        }

        private void btNhanvien_ItemClick_2(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmNhanvien) return;
            var frm = new catalog.FrmNhanvien() { MdiParent = this };

            frm.Show();
        }

        private void btDoituong_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmDoituong) return;
            var frm = new catalog.FrmDoituong() { MdiParent = this };

            frm.Show();
        }

        private void btBenhnhan_ItemClick_2(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmBenhnhan) return;
            var frm = new catalog.FrmBenhnhan() { MdiParent = this };

            frm.Show();
        }

        private void btTrangthaikham_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmTrangthaikham) return;
            var frm = new catalog.FrmTrangthaikham() { MdiParent = this };

            frm.Show();
        }

        private void btChucdanh_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmChucdanh) return;
            var frm = new catalog.FrmChucdanh() { MdiParent = this };

            frm.Show();
        }

        private void btPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmPhong) return;
            var frm = new catalog.FrmPhong() { MdiParent = this };

            frm.Show();
        }

        private void btDonvitinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmDonvitinh) return;
            var frm = new catalog.FrmDonvitinh() { MdiParent = this };

            frm.Show();
        }

        private void btdichvucls_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmDichvucls) return;
            var frm = new catalog.FrmDichvucls() { MdiParent = this };

            frm.Show();
        }

      

        private void btLichsubenhnhan_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmXemlichsubenh) return;
            var frm = new catalog.FrmXemlichsubenh() { MdiParent = this };

            frm.Show();

        }

        private void btPhieukhamtheotrangthai_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Thongke_Baocao.FrmPhieukhamtheotrangthaikham) return;
            var frm = new Thongke_Baocao.FrmPhieukhamtheotrangthaikham() { MdiParent = this };

            frm.Show();
        }

        private void btdangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (btdangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                btdangnhap.Caption = STR_LOGIN;

                barDongtacca_ItemClick(sender, e);
            }

            catalog.Frmdangnhap x = new catalog.Frmdangnhap();
            x.ShowDialog();

            if (_sss.Login)
            {
                //bsiUser.Caption = _sss.Name;
                bsiMA_NV.Caption = _sss.Acc;
                btdangnhap.Caption = STR_LOGOUT;

                //rpDanhmuc.Visible = true;
                //rpThongke.Visible = true;
                //rpgNguoidung.Visible = true;
                //rpgDangky.Visible = true;
                //bbiDoimatkhau.Visibility = BarItemVisibility.Always;
            }
            else
            {
              //  rpDanhmuc.Visible = false;
              //  rpThongke.Visible = false;
                //rpgNguoidung.Visible = false;
                //rpgDangky.Visible = false;
                //rpgDiemthi.Visible = false;
                //bbiDoimatkhau.Visibility = BarItemVisibility.Never;
            }

            EnableMenu();

        }

        private void bartiepnhanbenh_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmTiepnhanbenh) return;
            var frm = new catalog.FrmTiepnhanbenh() { MdiParent = this };

            frm.Show();
        }

        private void btbenhnhan1_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmBenhnhan) return;
            var frm = new catalog.FrmBenhnhan() { MdiParent = this };

            frm.Show();
        }

        private void phieukhambacsi_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.Frmcapnhatphieukham) return;
            var frm = new catalog.Frmcapnhatphieukham() { MdiParent = this };

            frm.Show();
        }

        private void iAbout_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void bbicanlamsan_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmKetquaxetnghiemCLS) return;
            var frm = new catalog.FrmKetquaxetnghiemCLS() { MdiParent = this };

            frm.Show();
        }

        private void btitiepnhanbenh_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmTiepnhanbenh) return;
            var frm = new catalog.FrmTiepnhanbenh() { MdiParent = this };

            frm.Show();
        }

       

        private void btikhoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmKhoa) return;
            var frm = new catalog.FrmKhoa() { MdiParent = this };

            frm.Show();
        }

        private void btloaidichvu_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmLoaidichvu) return;
            var frm = new catalog.FrmLoaidichvu() { MdiParent = this };

            frm.Show();
        }

        private void barButtonItem1_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Thongke_Baocao.FrmThongkedanhsachnhanvien) return;
            var frm = new Thongke_Baocao.FrmThongkedanhsachnhanvien() { MdiParent = this };

            frm.Show();
        }

        private void btphieusudungdichvu1_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmPhieusudungdichvu_thanhtoan) return;
            var frm = new catalog.FrmPhieusudungdichvu_thanhtoan() { MdiParent = this };

            frm.Show();
        }


    }
}